// -*- coding: utf-8 -*- 
/**
 * Project: Java8InActionT
 * Creator: yanking
 * Create time: 2022-02-19 16:29
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.StreamTrain.forkAndJoin;

import org.junit.jupiter.api.Test;

import java.util.concurrent.ForkJoinPool;
import java.util.stream.LongStream;

public class runForkAndJoin {
    public long forkJoinSum(long n) {
        long[] number = LongStream.rangeClosed(1, n).toArray();
        forkAndJoin task = new forkAndJoin(number);
        return new ForkJoinPool().invoke(task); 
    }

    public int countWordIteratively(String s) {
        // check the each word's space number in front
        int counter = 0;
        boolean lastSpace = true;
        for (char c : s.toCharArray()) {
            if (Character.isWhitespace(c)) {
                lastSpace = true;
            } else {
                if (lastSpace) {
                    ++counter;
                }
                lastSpace = false;

            }
        }
        return counter;
    }

    @Test
    public void shout00() {
        System.out.println(forkJoinSum(10000000));
    }

    @Test
    public void shout01() {
        String sentence = " hello jim    where are you now   ";
        System.out.println(countWordIteratively(sentence));
    }


}
